package com.vogue.supplymall.order.controller;

import com.vogue.supplymall.common.domain.dto.ControllerResultInfo;
import com.vogue.supplymall.common.domain.dto.RefundMaxCountInfo;
import com.vogue.supplymall.common.domain.dto.RefundOrderDetailInfo;
import com.vogue.supplymall.common.domain.dto.UserInfo;
import com.vogue.supplymall.common.exception.DataNotFindException;
import com.vogue.supplymall.order.common.CheckOrderUtils;
import com.vogue.supplymall.order.domain.biz.RefundOrderDetailBiz;
import org.apache.shiro.SecurityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.annotation.Resource;

/**
 * The type Refund order detail list controller.
 * 退单详情controller
 */
@Controller
public class RefundOrderDetailListController extends BaseController {
    public static final Logger log = LoggerFactory.getLogger(RefundOrderDetailListController.class);

    @Resource
    private RefundOrderDetailBiz refundOrderDetailBiz;

    /**
     * Gets order detail.
     * 获取退单详情
     *
     * @param appver                the appver
     * @param refundOrderDetailInfo the refund order detail infrefundMaxQuantityo
     * @return the order detail
     */
    @RequestMapping(value = "/is/{appver}/order/refundDetail", method = RequestMethod.POST)
    public ResponseEntity<Object> getOrderDetail(@PathVariable("appver") String appver, @RequestBody RefundOrderDetailInfo refundOrderDetailInfo) {
        log.info("Get Order Detail start >>>>>> ");
        UserInfo info = new UserInfo();
        if (SecurityUtils.getSubject().isAuthenticated()) {
            info = (UserInfo) SecurityUtils.getSubject().getPrincipal();
            log.info("获取登信息：" + info.getLoginId());
            if (CheckOrderUtils.checkRefundOrderDetailParameter(refundOrderDetailInfo)) {
                log.info(" 参数错误！ ");
                throw new DataNotFindException("parameter error");
            }
        } else {
            log.info("获取登信息失败！");
        }

        ControllerResultInfo resultInfo = new ControllerResultInfo();
        resultInfo.setResult(true);
        resultInfo.setData(refundOrderDetailBiz.findRefundOrderDetail(refundOrderDetailInfo.getRefundorderid()));
        log.info(" <<<<<< Get Order Detail end");
        return new ResponseEntity<>(resultInfo, HttpStatus.OK);
    }

    /**
     * Gets refund max quantity.
     * 获取退单最大数量
     *
     * @param appver             the appver
     * @param refundMaxCountInfo the refund max count info
     * @return the refund max quantity
     */
    @RequestMapping(value = "/is/{appver}/order/refundMaxQuantity", method = RequestMethod.POST)
    public ResponseEntity<Object> getRefundMaxQuantity(@PathVariable("appver") String appver, @RequestBody RefundMaxCountInfo refundMaxCountInfo) {
        log.info("Get refundMaxQuantitystart >>>>>> ");

        UserInfo info = new UserInfo();
        if (SecurityUtils.getSubject().isAuthenticated()) {
            info = (UserInfo) SecurityUtils.getSubject().getPrincipal();
            log.info("获取登信息：" + info.getLoginId());
            if (CheckOrderUtils.checkRefundMaxQuantityParameter(refundMaxCountInfo)) {
                log.info(" 参数错误！ ");
                throw new DataNotFindException("parameter error");
            }
        } else {
            log.info("获取登信息失败！");
        }

        ControllerResultInfo resultInfo = new ControllerResultInfo();
        resultInfo.setResult(true);
        resultInfo.setData(refundOrderDetailBiz.getRefundMaxQuantity(refundMaxCountInfo));
        log.info(" <<<<<< Get Order Detail end");
        return new ResponseEntity<>(resultInfo, HttpStatus.OK);

    }
}
